<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"bamboowine.gitee.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="动态规划&#x2F;中心扩散法">
<meta property="og:type" content="article">
<meta property="og:title" content="回文子串">
<meta property="og:url" content="https://bamboowine.gitee.io/2021/07/30/leetcode/%E5%9B%9E%E6%96%87%E5%AD%90%E4%B8%B2/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="动态规划&#x2F;中心扩散法">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/BambooWine/MyPhotos/raw/master/img/image-20210729233240197.png">
<meta property="og:image" content="https://gitee.com/BambooWine/MyPhotos/raw/master/img/image-20210730112802116.png">
<meta property="og:image" content="https://gitee.com/BambooWine/MyPhotos/raw/master/img/image-20210730113240776.png">
<meta property="og:image" content="https://gitee.com/BambooWine/MyPhotos/raw/master/img/image-20210730113654175.png">
<meta property="og:image" content="https://gitee.com/BambooWine/MyPhotos/raw/master/img/image-20210730160846651.png">
<meta property="article:published_time" content="2021-07-30T07:04:28.000Z">
<meta property="article:modified_time" content="2021-07-30T08:21:49.626Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="动态规划">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/BambooWine/MyPhotos/raw/master/img/image-20210729233240197.png">

<link rel="canonical" href="https://bamboowine.gitee.io/2021/07/30/leetcode/%E5%9B%9E%E6%96%87%E5%AD%90%E4%B8%B2/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>回文子串 | Hexo</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      
      <!-- 修改title -->
      <h1 class="site-title"> BambooWine's Notes </h1>
      <p class="site-subtitle" style="opacity: 1; top: 0px;">努力吧, 朋友~</p>
      <!-- <h1 class="site-title">Hexo</h1> -->

      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://bamboowine.gitee.io/2021/07/30/leetcode/%E5%9B%9E%E6%96%87%E5%AD%90%E4%B8%B2/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="John Doe">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Hexo">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          回文子串
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2021-07-30 15:04:28 / 修改时间：16:21:49" itemprop="dateCreated datePublished" datetime="2021-07-30T15:04:28+08:00">2021-07-30</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%AE%97%E6%B3%95/" itemprop="url" rel="index"><span itemprop="name">算法</span></a>
                </span>
            </span>

          
            <div class="post-description">动态规划/中心扩散法</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="647-回文子串"><a href="#647-回文子串" class="headerlink" title="647 回文子串"></a>647 回文子串</h1><h2 id="1-题目"><a href="#1-题目" class="headerlink" title="1. 题目"></a>1. 题目</h2><p><strong><a href="https://leetcode-cn.com/problems/palindromic-substrings/" target="_blank" rel="noopener">题目链接</a></strong></p>
<p><img src="https://gitee.com/BambooWine/MyPhotos/raw/master/img/image-20210729233240197.png" alt="image-20210729233240197"></p>
<h2 id="2-题目分析"><a href="#2-题目分析" class="headerlink" title="2. 题目分析"></a>2. 题目分析</h2><p>题目言简意赅，就是找回文串的的数目。</p>
<p>再看一下数据量，字符串的长度不会超过1000，故暴力解法大概率是过不去的，时间复杂度在10^9量级。</p>
<p>所谓暴力法：确定每一个起点，再确定每一个终点，最后判断该子串是否为回文串。</p>
<p>下面介绍<strong>动态规划</strong>、<strong>中心扩散法</strong>。</p>
<h2 id="3-动态规划"><a href="#3-动态规划" class="headerlink" title="3. 动态规划"></a>3. 动态规划</h2><h3 id="3-1-二维dp"><a href="#3-1-二维dp" class="headerlink" title="3.1 二维dp"></a>3.1 二维dp</h3><h4 id="3-1-1-状态定义"><a href="#3-1-1-状态定义" class="headerlink" title="3.1.1 状态定义"></a>3.1.1 状态定义</h4><p><code>dp[i][j]</code>：字符串s的[i, j]范围的子串是否是回文串</p>
<p>i ∈ [0, n]</p>
<p>j ∈ [0, n]</p>
<p>其中 <code>i ≤ j, n = s.size()</code></p>
<h4 id="3-1-2-状态转移方程"><a href="#3-1-2-状态转移方程" class="headerlink" title="3.1.2 状态转移方程"></a>3.1.2 状态转移方程</h4><ul>
<li><p>若<code>i == j</code>，因为只有一个字母，则s的[i，j]肯定是回文串</p>
</li>
<li><p>若<code>i + 1 == j</code>，因为只有两个字母，所以若<code>s[i] == s[j]</code>，则s的[i，j]为回文串</p>
</li>
<li><p>若<code>dp[i + 1][j - 1] = true</code>，即s的[i+1，j-1]子串为回文串，如果此时<code>s[i] == s[j]</code>，那么s的[i，j]子串也是为回文串。</p>
</li>
<li><p>若<code>dp[i + 1][j - 1] = false</code>，即s的[i+1，j-1]子串不是回文串，则s的[i，j]肯定也不是回文串</p>
</li>
</ul>
<p>综上所述，可以得到<strong>状态转移方程</strong>：</p>
<ul>
<li>如果<code>j - i &lt;= 1</code> ，则 <code>dp[i][j] = s[i] == s[j]</code></li>
<li>否则 <code>dp[i][j] = dp[i + 1][j - 1] &amp;&amp; s[i] == s[j]</code></li>
</ul>
<h4 id="3-1-3-dp数组初始化"><a href="#3-1-3-dp数组初始化" class="headerlink" title="3.1.3 dp数组初始化"></a>3.1.3 dp数组初始化</h4><ul>
<li><p>dp数组全部元素设置为false</p>
</li>
<li><p>至于是否有给一些元素设置true的必要，这里进行一个简单的分析：</p>
<p><img src="https://gitee.com/BambooWine/MyPhotos/raw/master/img/image-20210730112802116.png" alt="image-20210730112802116"></p>
<p>由于<code>i &lt;= j</code>，所以如图黑色区域不需要填写（如上图所示）；</p>
<p><img src="https://gitee.com/BambooWine/MyPhotos/raw/master/img/image-20210730113240776.png" alt="image-20210730113240776"></p>
<p>而<code>i == j</code> 和<code>i + 1 == j</code> 的元素可以填写（如上图所示）；至于剩余的黄色区域则根据当前表格的左下角表格结合s[i]，s[j]来填写（如下图所示）。</p>
<p><img src="https://gitee.com/BambooWine/MyPhotos/raw/master/img/image-20210730113654175.png" alt="image-20210730113654175"></p>
</li>
</ul>
<h4 id="3-1-4-完整代码"><a href="#3-1-4-完整代码" class="headerlink" title="3.1.4 完整代码"></a>3.1.4 完整代码</h4><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Solution</span> &#123;</span></span><br><span class="line"><span class="keyword">public</span>:</span><br><span class="line">    <span class="function"><span class="keyword">int</span> <span class="title">countSubstrings</span><span class="params">(<span class="built_in">string</span> s)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span> n = s.<span class="built_in">size</span>();</span><br><span class="line">        <span class="comment">// dp[i][j] 字符串s的[i,j]范围是否是回文串</span></span><br><span class="line">        <span class="function"><span class="built_in">vector</span>&lt;<span class="built_in">vector</span>&lt;<span class="keyword">bool</span>&gt;&gt; <span class="title">dp</span><span class="params">(n, <span class="built_in">vector</span>&lt;<span class="keyword">bool</span>&gt;(n, <span class="literal">false</span>))</span></span>;</span><br><span class="line">        <span class="keyword">int</span> res = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i = n - <span class="number">1</span>; i &gt;= <span class="number">0</span>; --i)&#123;</span><br><span class="line">            <span class="keyword">for</span>(<span class="keyword">int</span> j = n - <span class="number">1</span>; j &gt;= i; --j)&#123;</span><br><span class="line">                <span class="keyword">if</span>(j - i &lt;= <span class="number">1</span>) dp[i][j] = s[i] == s[j];</span><br><span class="line">                <span class="keyword">else</span> dp[i][j] = dp[i + <span class="number">1</span>][j - <span class="number">1</span>] &amp;&amp; s[i] == s[j];</span><br><span class="line">                res += dp[i][j];</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> res;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<h3 id="3-2-一维dp"><a href="#3-2-一维dp" class="headerlink" title="3.2 一维dp"></a>3.2 一维dp</h3><p>由二维dp的代码可以看出，dp数组的第i行的值依赖于第i+1行的值，所以可以进行<strong>空间优化</strong>——使用<strong>滚动数组</strong>。</p>
<p>同时由于dp[j]依赖于dp[j-1]，所以仅用一个数组，倒叙遍历即可。</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Solution</span> &#123;</span></span><br><span class="line"><span class="keyword">public</span>:</span><br><span class="line">    <span class="function"><span class="keyword">int</span> <span class="title">countSubstrings</span><span class="params">(<span class="built_in">string</span> s)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span> n = s.<span class="built_in">size</span>();</span><br><span class="line">        <span class="function"><span class="built_in">vector</span>&lt;<span class="keyword">bool</span>&gt; <span class="title">dp</span><span class="params">(n, <span class="literal">false</span>)</span></span>;</span><br><span class="line">        <span class="keyword">int</span> res = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i = n - <span class="number">1</span>; i &gt;= <span class="number">0</span>; --i)&#123;</span><br><span class="line">            <span class="keyword">for</span>(<span class="keyword">int</span> j = n - <span class="number">1</span>; j &gt;= i; --j)&#123;</span><br><span class="line">                <span class="keyword">if</span>(j - i &lt;= <span class="number">1</span>) dp[j] = s[i] == s[j];</span><br><span class="line">                <span class="keyword">else</span> dp[j] = dp[j - <span class="number">1</span>] &amp;&amp; s[i] == s[j];</span><br><span class="line">                res += dp[j];</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> res;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<h2 id="4-中心扩散法"><a href="#4-中心扩散法" class="headerlink" title="4. 中心扩散法"></a>4. 中心扩散法</h2><p>中心扩散法：<strong>选定一个中心，然后同时向左向右扩散，关于奇数长度和偶数长度的字符串可以用不同的中心起止位置来解决</strong>。如下图所示。</p>
<p><img src="https://gitee.com/BambooWine/MyPhotos/raw/master/img/image-20210730160846651.png" alt="image-20210730160846651"></p>
<p><strong>以数组的每一个索引位置作为奇数长度和偶数长度的中心，然后不断向外扩散，直到当前子串不是回文串，结束扩散</strong>。</p>
<p>表面上看中心扩散法和暴力解法思路上并无大的区别，但是为什么效率相差这么多呢？</p>
<p>这是因为<strong>中心扩散法会利用先前的判断结果</strong>：例如 <code>aba</code>为回文串，向外扩散一次——<code>cabac</code>，只要比较最外侧的字符是否相同就可以很容易地判断是否为回文串；但是如果使用暴力解法，判断<code>aba</code>为回文串后，访问到<code>abac</code> 就需要再次经历一次<strong>回文判断</strong>，效率极低！</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Solution</span> &#123;</span></span><br><span class="line"><span class="keyword">public</span>:</span><br><span class="line">    <span class="function"><span class="keyword">int</span> <span class="title">countSubstrings</span><span class="params">(<span class="built_in">string</span> s)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span> n = s.<span class="built_in">size</span>(), res = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n; ++i)&#123;</span><br><span class="line">            res += expand(s, i, i);</span><br><span class="line">            res += expand(s, i, i + <span class="number">1</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> res;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 中心扩散法的expand函数</span></span><br><span class="line">    <span class="function"><span class="keyword">int</span> <span class="title">expand</span><span class="params">(<span class="built_in">string</span>&amp; s, <span class="keyword">int</span> l, <span class="keyword">int</span> r)</span></span>&#123;</span><br><span class="line">        <span class="keyword">int</span> res = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">while</span>(l &gt;= <span class="number">0</span> &amp;&amp; r &lt; s.<span class="built_in">size</span>())&#123;</span><br><span class="line">            <span class="keyword">if</span>(s[l] == s[r]) &#123; ++res; --l; ++r; &#125;</span><br><span class="line">            <span class="keyword">else</span> <span class="keyword">break</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> res;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>时间复杂度O(n^2)，空间复杂度O(1)。</p>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92/" rel="tag"># 动态规划</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/07/29/leetcode/%E7%9B%AE%E6%A0%87%E5%92%8C/" rel="prev" title="目标和 (动态规划/01背包)">
      <i class="fa fa-chevron-left"></i> 目标和 (动态规划/01背包)
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/08/08/leetcode/%E5%88%A0%E9%99%A4BST%E8%8A%82%E7%82%B9/" rel="next" title="删除BST的节点">
      删除BST的节点 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#647-回文子串"><span class="nav-number">1.</span> <span class="nav-text">647 回文子串</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-题目"><span class="nav-number">1.1.</span> <span class="nav-text">1. 题目</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-题目分析"><span class="nav-number">1.2.</span> <span class="nav-text">2. 题目分析</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-动态规划"><span class="nav-number">1.3.</span> <span class="nav-text">3. 动态规划</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-二维dp"><span class="nav-number">1.3.1.</span> <span class="nav-text">3.1 二维dp</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#3-1-1-状态定义"><span class="nav-number">1.3.1.1.</span> <span class="nav-text">3.1.1 状态定义</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-1-2-状态转移方程"><span class="nav-number">1.3.1.2.</span> <span class="nav-text">3.1.2 状态转移方程</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-1-3-dp数组初始化"><span class="nav-number">1.3.1.3.</span> <span class="nav-text">3.1.3 dp数组初始化</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-1-4-完整代码"><span class="nav-number">1.3.1.4.</span> <span class="nav-text">3.1.4 完整代码</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-一维dp"><span class="nav-number">1.3.2.</span> <span class="nav-text">3.2 一维dp</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-中心扩散法"><span class="nav-number">1.4.</span> <span class="nav-text">4. 中心扩散法</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt=" BambooWine "
      src="/images/avatar.jpg">

  <!-- 修改作者 -->
  <p class="site-author-name" itemprop="name"> BambooWine </p>
  <!-- <p class="site-author-name" itemprop="name">John Doe</p> -->

  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">21</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
        <span class="site-state-item-count">2</span>
        <span class="site-state-item-name">分类</span>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">6</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  
  <span class="author" itemprop="copyrightHolder">BambooWine</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
